<?php defined('SEJUJOPEFDNGJSL') or exit('Access denied');?>
<?php
//获得领导人即直接上线信息
if($r['id']==8501){
    $sxid=8501;
}else{
  $sxid=$r['introducer_id'];
}
$leader=$member->getuserinfo($sxid);

?>
<style type="text/css">
  .MzTreeView{font-size: 14px;line-height: 28px;}
</style>
<?php require("topbut.php");
?>
<div class="panel panel-inverse">
    <div class="panel-heading">
        <h4 class="panel-title">我的团队</h4>
    </div>
    <div class="panel-body">
        <div class="alert m-b-0" style="background: rgba(134,195,65, .5);border:1px solid rgba(134,195,65, 1);">
            <div class="row">
                <div class="col-md-12" style="display:none">
                    推荐人：<span class="red"><?php if(isset($leader['nick_name'])) echo $leader['real_name']?></span>
                </div>
                <div class="col-md-12">
                    用户名：<span class="red"><?php if(isset($r['uname'])) echo $r['uname']?></span>
                </div>
                <div class="col-md-12">
                    手机号：<span class="red"><?php if(isset($r['phone'])) echo $r['phone']?></span>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    我的推荐链接：</span><a id="ttlink" style="color:#de0519;" href="/r1.php?tid=<?php echo $r['uname']?>"><?php echo YUMING;?>r1.php?tid=<?php echo $r['uname']?></a>
                </div>
                <div class="clear"></div>
                  <div style="margin-left: 10px;margin-top: 10px;">
    <?php
    $member_name = $_username;
    $image_name = "./upfile/ewm/ewm_".$member_name.".png";
    if(!is_file($image_name)){
      include_once('./phpqrcode/phpqrcode.php');
      @QRcode::png("http://".$_SERVER["HTTP_HOST"].'/r1.php?tid='.$member_name, $image_name, 'L', 5, 2);
      chmod($image_name,444);
      $logo = './upfile/ewm/ewmlogo.jpg';
      $logos = imagecreatefromstring(file_get_contents($image_name));
      $image_name = imagecreatefromstring(file_get_contents($logo));
      $QR_width = imagesx($image_name);
      $QR_height = imagesy($image_name);
      $logo_width = imagesx($logos);
      $logo_height = imagesy($logos);
      $from_width = ($logo_width - $QR_width) / 2;
      $from_height = ($logo_height - $QR_height) / 2;
      imagecopyresampled($logos, '', $from_width, $from_height, 0, 0, $QR_width, $QR_height, $QR_width, $QR_height);
      $file_name = "./upfile/ewm/ewmwbg_".$member_name.".png";
      $file_address = "ewmwbg_".$member_name.".png";
      imagepng($logos,$file_name);
      chmod($file_name,444);
    }else{
      $file_address = "ewmwbg_".$member_name.".png";
    }
    ?>
      <img width="110px" height="110px" src="./upfile/ewm/<?php echo $file_address; ?>" />
    </div>
            </div>
        </div>
        <div>

        <form action="<?php echo geturl();?>" method="post" class="form-horizontal">
          <div class="row">
            <div class="col-md-3" style="margin-bottom: 5px;">
              <input type="text" name='ssname' value="" class="form-control">
            </div>
            <div class="col-md-3" style="margin-bottom: 5px;">
              <input type="submit" name="submit" value="搜索用户" class="btn btn-md btn-warning" />
            </div>
          </div>
        </form>
        </div>
        <?php
        $level=1;
        $qid=getnums($_GET["qid"],$_userid);
        if($_POST['submit']=='搜索用户'){
          $ssname=checkstr($_POST['ssname']);
          $db->query("select id from ld_user_account where uname='".$ssname."'",2);
          $ids=$db->rs['id'];
          if(!empty($ids)){
            $qid=$ids;
          }else{
            $qid=getnums($_GET["qid"],$_userid);

          }
        }
        $sql="select team_number,id,uname,user_level,is_passed,service_center_status,introducer_id,recommend_unum,leader_number,parents_ids from ld_user_account where id='$qid'";
        $db->query($sql,2);
        $rs=$db->rs;
        if(empty($rs)){
          msg_b('用户不存在');
        }

        if(!strstr($rs['parents_ids'],",".$_userid.",") && $rs["id"]!=$_userid){
           msg_b('跳转失败!');
        }

        echo '<script type="text/javascript" src="'.SITETHEME.'js/tree.js"></script>
        <div class="tudiv">
          <span class="yellowc">头像信息</span>：[用户名] [代数] [直推人数][团队人数]&nbsp;&nbsp;&nbsp;&nbsp;
          <span class="yellowc">图像表示</span>：<img src="'.SITETHEME.'tree/member.gif">&nbsp;用户&nbsp;&nbsp;&nbsp;&nbsp;
        </div>
        <p><a href="'.$GLOBALARR['curl'].'&level='.$level.'&qid='.($rs['introducer_id']>$_userid?$rs['introducer_id']:$_userid).'" class="btn btn-success">返回上一层</a></p>
        <div id="ztree" style="padding-left:10px"></div>';
        ?>
        <script type="text/javascript">
        function InitShowTreeInfo(tree){
        <?php

        $ic=gettjicon(array($rs['is_passed'],$rs['service_center_status']));
        $m=$member->getuserinfo($rs["uname"],1);

         $is_gua=0;
            $db->query("select id from ld_give_help where xf_type=2 and  uid=".$rs['id']." limit 1",2);
            if($db->rs['id']){
              $db->query("select id from ld_transfer_coin where cuid=".$rs['id']."  and ctype=0 and type=0 and is_cross=1 limit 1",2);
              if(!$db->rs['id']){
                 $is_gua=1;
              }
            }
            if($is_gua==0){
              $gua="";
            }else{
              $gua="已排单";
        }
        if($m['is_freezed']==0){
          $staus="正常";
        }else{
            $staus="冻结";
        }



        $par=array_reverse(explode(',',$m['parents_ids']));
            //搜索第几代
        $dai=(array_search($_userid, $par)).'代';

        echo "tree.nodes['0_".$rs['id']."'] = 'text:<span ".$ic[1].">".$rs["uname"]." [".$dai."]  [".$rs['recommend_unum']."][".$rs['team_number']."]</span>;url:javascript:void(0);method:goUrl();".$ic[0]."'" ."\n";

        maketree($rs['id']);
        ?>
        }

        var tree = new MzTreeView("tree");
          tree.icons["zero"] = "user.gif";//
          tree.icons["member"] = "member.gif";//
          tree.icons["agent"] = "filiale.gif";//
          tree.icons["admin"] = "manager.gif";//
          tree.setIconPath("theme/tree/"); //可用相对路径
          InitShowTreeInfo(tree);
          tree.setTarget("_self");
          document.getElementById("ztree").innerHTML = tree.toString();

        </script>

        <?php
        function maketree($vid){
          global $GLOBALARR,$db,$member,$level,$rs,$_userid;

          if($level!=-1){
            $qsql=" and leader_number<=".($rs['leader_number']+$level);
          }else{
            $qsql="";
          }


          $sql="select team_number,id,uname,user_level,is_passed,service_center_status,introducer_id,recommend_unum,leader_number from ld_user_account where introducer_id=$vid  $qsql order by id asc";
          $db->query($sql);
          $row=$db->rs;
          foreach($row as $k=>$v){
            $ic=gettjicon(array($v['is_passed'],$v['service_center_status']));

            $m=$member->getuserinfo($v["uname"],1);
            //搜索用户是否挂单否
            $is_gua=0;
            $db->query("select id from ld_give_help where xf_type=2 and  uid=".$v['id']." limit 1",2);
            if($db->rs['id']){
              $db->query("select id from ld_transfer_coin where cuid=".$v['id']."  and ctype=0 and type=0 and is_cross=1 limit 1",2);
              if(!$db->rs['id']){
                 $is_gua=1;
              }
            }
            if($is_gua==0){
              $gua="";
            }else{
              $gua="已排单";
            }
            if($m['is_freezed']==0){
                $sta="正常";
            }else{
                 $sta="冻结";
            }
            $par=array_reverse(explode(',',$m['parents_ids']));
            //搜索第几代
            $dai=(array_search($_userid, $par)).'代';
            // var_dump($par);
            // var_dump($_userid);

            echo "tree.nodes['".$v["introducer_id"]."_".$v["id"]."'] = 'text:<span ".$ic[1].">".$v["uname"]."</span> <font style=color:#000>[".$dai."][".$v["recommend_unum"]."][".$v["team_number"]."]</font>;url:".$GLOBALARR['curl']."&qid=".$v["id"]."&level=".$level.";method:goUrl();".$ic[0]."'"."\n";

            maketree($v["id"]);

          }
        }

        function gettjicon($arr){
          $icon='';$color;
          if($arr[0]==1){
            $icon="icon:member";
            $color='style=color:#000';
          }else{
            $icon="icon:zero";
            $color='style=color:#000';
          }

          if($arr[1]==2){
            $icon="icon:agent";
            $color='style=color:#000';
          }

          return array($icon,$color);
        }
        ?>
    </div>
</div>
